class Solution {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
          ListNode c1 = l1 ;
          ListNode c2 = l2 ;
          int tmp = 0 ;
          int sum = 0 ;
          ListNode newHead = new ListNode() ;
           ListNode cur = newHead ;
         while(c1 != null && c2 != null){
             sum = (c1.val + c2.val + tmp ) % 10 ;
             tmp = (c1.val + c2.val + tmp ) / 10 ;
             ListNode node = new ListNode(sum) ;
              cur.next = node ;
              cur = cur.next ;
              c1=c1.next ;
              c2 = c2.next ;
         }
         while(c2 != null){
             sum = (c2.val + tmp) % 10 ;
             tmp = (c2.val + tmp) / 10 ;
           ListNode node = new ListNode(sum) ;
              cur.next = node ;
              cur = cur.next ;
              c2 = c2.next ;
         }
          while(c1 != null){
             sum = (c1.val + tmp) % 10 ;
             tmp = (c1.val + tmp) / 10 ;
           ListNode node = new ListNode(sum) ;
              cur.next = node ;
               cur = cur.next ;
              c1 = c1.next ;
         }
         if(tmp != 0){
            ListNode node = new ListNode(tmp) ;
             cur.next = node ;
         }
         return newHead.next ;
     

    }
}